package com.ftg.learn.chapter05.config;

import com.mysql.cj.jdbc.MysqlDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @author kangjx
 * @createTime 2022/11/8
 */
@Configuration
public class DatabaseConfig {

    @Bean
    @Primary
    public DataSource initDatasource(){

        //MysqlDataSource

        //用了druid 连接池 初始化一些连接 将druid去掉 直接连接

        MysqlDataSource mysql = new MysqlDataSource();
        mysql.setURL("jdbc:mysql://localhost:3306/ad");
        mysql.setUser("root");
        //密码是对的 .... 过期时间 ,它过期 一直重新连接 mysql
        mysql.setPassword("Love0913@kjx");
        return mysql;
    }

}
